1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import javax.swing.*;
32 import javax.swing.text.BadLocationException;
33 import javax.swing.text.Highlighter;
34 import javax.swing.text.JTextComponent;
35 import java.awt.*;
36
37 public class bug6771184 {
38 public static void main(String[] args) {
39 SwingUtilities.invokeLater(new Runnable() {
40 public void run() {
41 JTextArea textArea = new JTextArea("Tested string");
42
43 Highlighter highlighter = textArea.getHighlighter();
44 Highlighter.HighlightPainter myPainter = new Highlighter.HighlightPainter() {
45 public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
46 }
47 };
48
49 int negativeTestedData[][] = {{50, 0},
50 {-1, 1},
51 {-5, -4},
52 {Integer.MAX_VALUE, Integer.MIN_VALUE},
53 {Integer.MIN_VALUE, Integer.MAX_VALUE},
54 {Integer.MIN_VALUE, Integer.MIN_VALUE}};
55
56 for (int[] data : negativeTestedData) {
57 try {
58 highlighter.addHighlight(data[0], data[1], myPainter);
59
60 throw new RuntimeException("Method addHighlight() does not throw BadLocationException for (" +
61 data[0] + ", " + data[1] + ") ");
62 } catch (BadLocationException e) {
63
64 }
65
66 Object objRef;
67
68 try {
69 objRef = highlighter.addHighlight(0, 1, myPainter);
70 } catch (BadLocationException e) {
71 throw new RuntimeException("highlighter.addHighlight(0, 1, myPainter) throws exception", e);
72 }
73
74 try {
75 highlighter.changeHighlight(objRef, data[0], data[1]);
76
77 throw new RuntimeException("Method changeHighlight() does not throw BadLocationException for (" +
78 data[0] + ", " + data[1] + ") ");
79 } catch (BadLocationException e) {
80
81 }
82 }
83 }
84 });
85 }
86 }